<?php

namespace App\Models\CacheModel\zl4;

use App\Models\Api\BaseCache;
use think\Log;
use AstroTool\Cache\CacheManage;

class Zl4GoodTimeType extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zl4_good_time_type';

    protected $cacheModel = 'horoscope.good_time_type';

    /**
     * 八字 吉日吉时 获取所有选项类型
     * @return array
     * @throws \Exception
     */
    public function getTypes()
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel)->getDataAndSet(function ()
        {
            try
            {
                $data = $this->where(['status' => 1])->order('sort desc')->column('name,icon', 'id');

                $data = arrayKeyData2int($data, ['id']);

                return json_encode($data, JSON_UNESCAPED_UNICODE);
            }
            catch (\Exception $e)
            {
                Log::write('Zl4GoodTimeType model => getTypes()异常：' . $e->getMessage() . '失败行数：' . $e->getLine(), 'error');
                return '';
            }
        }, []);

        return $data ? json_decode($data, true) : [];
    }
}
